package com.rms.hkpc.control;

import android.content.Context;
import android.graphics.Color;
import android.graphics.drawable.GradientDrawable;
import android.os.Build;
import android.util.AttributeSet;
import android.view.LayoutInflater;
import android.view.View;
import android.widget.FrameLayout;
import android.widget.TextView;

import androidx.annotation.NonNull;
import androidx.annotation.Nullable;
import androidx.annotation.RequiresApi;

import com.rms.hkpc.R;

public class InsightView extends FrameLayout {

    private TextView tvTop, tvNum;

    public InsightView(@NonNull Context context) {
        super(context);
        init(context, null);
    }

    public InsightView(@NonNull Context context, @Nullable AttributeSet attrs) {
        super(context, attrs);
        init(context, attrs);
    }

    public InsightView(@NonNull Context context, @Nullable AttributeSet attrs, int defStyleAttr) {
        super(context, attrs, defStyleAttr);
        init(context, attrs);
    }

    @RequiresApi(api = Build.VERSION_CODES.LOLLIPOP)
    public InsightView(@NonNull Context context, @Nullable AttributeSet attrs, int defStyleAttr, int defStyleRes) {
        super(context, attrs, defStyleAttr, defStyleRes);
        init(context, attrs);
    }

    private void init(Context context, AttributeSet attrs) {
        if (attrs == null) {
            return;
        }

        View view = LayoutInflater.from(context).inflate(R.layout.item_insight, this, false);
        tvTop = view.findViewById(R.id.tv_top);
        tvNum = view.findViewById(R.id.tv_num);
        addView(view);
    }

    public void setTitle(String title) {
        tvTop.setText(title);
    }

    public void setNum(int num) {
        tvNum.setText(String.valueOf(num));
    }

    public void setNumColor(String color) {
        GradientDrawable gd = (GradientDrawable) tvNum.getBackground();
        gd.setStroke(6, Color.parseColor(color));
    }
}
